package com.kaifamiao.month05.day19;

import java.util.Arrays;

public class Test2 {

    // 定义一个学生类，类中有三个属性，姓名，性别，成绩，请设计一个sort方法对学生按照学生成绩 降序排序
    public static void sort(Student[] students) {
        int len = students.length - 1;
        for (int i = len; i >= 1; i--) {
            int minIndex = i;
            for (int j = i - 1; j >= 0; j--) {
                if (students[j].getScore() < students[minIndex].getScore()) {
                    minIndex = j;
                }
            }
            Student temp = students[i];
            students[i] = students[minIndex];
            students[minIndex] = temp;
        }
    }

    public static void main(String[] args) {
        Student stu1 = new Student("zs",'男',92.3);
        Student stu2 = new Student("ls",'女',88.5);
        Student stu3 = new Student("ww",'男',77.5);
        Student stu4 = new Student("sl",'女',65.2);
        Student stu5 = new Student("ll",'女',95.3);
        Student[] students = {stu1,stu2,stu3,stu4,stu5};
        sort(students);
        System.out.println(Arrays.toString(students));
    }
}

class Student {

    private String name;
    private char gender;
    private double score;


    public Student(String name, char gender, double score) {
        this.name = name;
        this.gender = gender;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", gender=" + gender +
                ", score=" + score +
                '}';
    }
}
